//
//  Fog.m
//  GameProject
//
//  Created by Blair Trusler on 05/03/2012.
//  Copyright (c) 2012 Blair Trusler. All rights reserved.
//

#import "GameHeader.h"

@implementation Fog


-(id) init
{
    if ((self = [super init])) {
        CCLOG(@"Loading Lighting Layer...");
        //Enable touch interaction:
        self.isTouchEnabled = NO;
        
        if (([platformType isEqualToString:@"Simulator"])||([platformType isEqualToString:@"iPad"])||([platformType isEqualToString:@"iPad 2 (WiFi)"])||([platformType isEqualToString:@"iPad 2 (GSM)"])||([platformType isEqualToString:@"iPad 2 (CDMA)"])){
            CCLOG(@"Enabling Lighting");
            CGSize screenSize = [CCDirector sharedDirector].winSize;
            
//                renderLayer = [CCRenderTexture renderTextureWithWidth:1500 height:1700];
                renderLayer = [CCRenderTexture renderTextureWithWidth:1024 height:768];
                renderLayer.position = ccp(screenSize.width/2, screenSize.height/2);
                [[renderLayer sprite] setBlendFunc: (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }];        
                [self addChild:renderLayer z:0];
                spotLight = [CCSpotLight initWithRenderTexture:renderLayer spotLightRadius:400.0f renderColor:ccc4(0, 0, 0, 255)];
                [self addChild:spotLight z:1 tag:999];
        
            
        }
        
        [self scheduleUpdate];
        
        CCLOG(@"Lighting Layer Loaded");
    }
    return self;
}


#pragma mark - dealloc
-(void) dealloc {
    [super dealloc];
}

-(void) update: (ccTime)deltaTime{

    if (([platformType isEqualToString:@"Simulator"])||([platformType isEqualToString:@"iPad"])||([platformType isEqualToString:@"iPad 2 (WiFi)"])||([platformType isEqualToString:@"iPad 2 (GSM)"])||([platformType isEqualToString:@"iPad 2 (CDMA)"])){
        spotLight.position = fogCoord;

    }
}

@end
